home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / latex Mode / latex.tcl next >
Encoding:
Text File  |  1997-12-19  |  10.2 KB  |  300 lines  |  [TEXT/ALFA]

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latex.tcl, version 4.1:  macros, menu, and key bindings for LaTeX users
  5. #
  6. #############################################################################
  7. #
  8. # version 1.1 and 1.2 (11/10/92) by Richard T. Austin <austin@eecs.umich.edu>
  9. # versions 2.0--3.2 and 3.2t (3/97) by Tom Scavo <trscavo@syr.edu>
  10. # versions 4.0 onwards (9/97) by Vince Darley <darley@fas.harvard.edu>
  11. # If you make improvements to this file, please share them!
  12. #
  13. # LaTeX 2.09 is no longer supported.  If someone wants to make the 
  14. # necessary changes to support it, they are welcome.
  15. #############################################################################
  16. #############################################################################
  17.  
  18. # Initialize TeX mode:
  19. alpha::mode TeX 4.1.1 texMenu \
  20.   {*.tex *.ltx *.dtx *.ins *.cls *.clo *.sty *.log *.aux \
  21.   *.bbl *.idx *.ind *.glo *.gls *.toc *.lof *.lot *.blg *.ilg } texMenu {
  22.     addMenu texMenu "•270"
  23.     set unixMode(latex) {TeX}
  24.         
  25.     alpha::package require Alpha 7.0
  26.     # Reset the search path so it will be rebuilt the next time it's needed:
  27.     set TeXSearchPath {}
  28.     
  29.     # Initialize TeX-related application signatures:
  30.     foreach app {tex viewDVI printDVI dvips viewPS printPS bibtex makeindex} {
  31.         ensureset ${app}Sig {}
  32.     }
  33.     
  34.     # Install the short LaTeX menu, by default:
  35.     ensureset useShortLaTeXMenu 1
  36.         
  37.     # Do not load AMS-LaTeX, by default:
  38.     ensureset useAMSLaTeX 0
  39.     
  40.     # To add a new fileset type, all we have to do is this:
  41.     set fileSetsTypesThing(tex) "tex"
  42.     lappend fileSetsTypes "tex"
  43. } maintainer {
  44.     "Vince Darley" darley@fas.harvard.edu <http://www.fas.harvard.edu/~darley/>
  45. } uninstall {this-directory} help {file "LaTeX Help"}
  46.  
  47. #############################################################################
  48. #
  49. # Autoload procedures
  50. #
  51. #############################################################################
  52.  
  53. proc dummyTeX {} {}
  54. proc texMenu {} {}
  55.  
  56. #############################################################################
  57. #
  58. # Flags and variables
  59. #
  60. #############################################################################
  61.  
  62. # Flags ---
  63.  
  64. # if a particular template requires a certain package, warn if it's not there.
  65. newPref f warnIfPackageNotIncluded 1 TeX
  66. newPref f buildPkgsSubmenu 0 TeX
  67. newPref f deleteEnvNoisily 1 TeX
  68. newPref f deleteObjNoisily 1 TeX
  69. newPref f promptNoisily 1 TeX
  70. newPref f runTeXInBack 0 TeX makeTypesetMenu
  71. newPref f searchNoisily 1 TeX
  72. newPref f smartDots 1 TeX
  73. newPref f smartQuotes 1 TeX
  74. # newPref f useBoxMacro 1 TeX
  75. newPref f useBrackets 0 TeX
  76. newPref f useDollarSigns 0 TeX shadowUseDollarSigns
  77. newPref f useStatusBar 1 TeX
  78. newPref f wordWrap 1 TeX
  79. newPref f electricTab 1 TeX
  80.  
  81. newPref v boxMacroNames {includegraphics includegraphics*} TeX shadowBoxMacroNames
  82. newPref v citeCommands {cite nocite citet citep citeyear} TeX shadowCiteRefCommands
  83. newPref v fillColumn {70} TeX
  84. newPref v funcExpr {\\(sub)*section(\[.*\]|\*)?({[^{}]*})?} TeX
  85. newPref v parseExpr {[^\{]*\{(.*)\}[^\}]*} TeX
  86. newPref v funcExprAlt {\\section(\[.*\]|\*)?({[^{}]*})?} TeX 
  87. newPref v leftFillColumn {0} TeX
  88. newPref v prefixString {% } TeX
  89. newPref v refCommands {ref eqref pageref} TeX shadowCiteRefCommands
  90. newPref v wrapBreak {(\w+|\\(\\\*?|[^A-Za-z\t\r*\s\]|[A-Za-z]+\*?))} TeX
  91. newPref v wrapBreakPreface {([^\w\]|.\\)} TeX
  92. newPref v wordBreak {([\w:-]+|\\(\\\*?|[^A-Za-z\t\r*\s\]|[A-Za-z]+\*?))} TeX
  93. newPref v wordBreakPreface {([^-\w:\]|.\\)} TeX
  94. set texParaCommands {\[|\]|begin|end|(protect\\)?label|(sub)*section\*?|subfigure|paragraph|centerline|centering|caption|chapter|item|bibitem|intertext|(protect\\)?newline|includegraphics\*?}
  95. newPref v TeXInputsFolder "" TeX shadowTeXInputs
  96.  
  97. newPref binding smartSubscripts "/_<U" TeX "" 1
  98. newPref binding smartSuperscripts "/^<U" TeX "" 1
  99.  
  100. #############################################################################
  101. #
  102. # Initialization
  103. #
  104. #############################################################################
  105.  
  106. hook::register activateHook makeTypesetMenu TeX
  107. proc makeTypesetMenu {name} {
  108.     menu::buildSome Typeset
  109. }
  110.  
  111. # registered only if we're using Textures
  112. proc TexturescloseHook {name} {
  113.     global Texturesconnections
  114.     if {[info exists Texturesconnections]} {
  115.         set winNames [map car $Texturesconnections]
  116.         if { [set pos [lsearch -exact $winNames $name]] > -1 } {
  117.             # Close Textures' connection:
  118.             global texAppSign
  119.             set TeXjob [cadr [lindex $Texturesconnections $pos]]
  120.             AEBuild -r '$texAppSign(Textures)' BSRs Disc Jobi $TeXjob
  121.             # Update list of connections:
  122.             set Texturesconnections [lreplace $Texturesconnections $pos $pos]
  123.         }
  124.     }
  125. }
  126.  
  127. proc TexturesLaunched {args} {
  128.     global Texturesconnections
  129.     set Texturesconnections ""    
  130. }
  131.  
  132. # The proc 'shadowtexSig' is executed automatically whenever 
  133. # the global variable 'texSig' is altered, say, by choosing
  134. # 'removedSavedSetting' on the Config menu.  Alpha now has
  135. # a nifty proc to handle all the hard work for us: (Vince)
  136. proc shadowtexSig {args} {
  137.     global packagesSubmenuItems TeXSearchPath texSig texAppSign
  138.     # Reset the Packages submenu so that it will be rebuilt:
  139.     set packagesSubmenuItems ""
  140.     message {Building LaTeX menu…}
  141.     buildLaTeXMenuQuietly
  142.     # Reset the search path so it will be rebuilt the next time it's needed:
  143.     set TeXSearchPath {}
  144.     # Set things up for Textures
  145.     if {[info exists texAppSign(Textures)] && \
  146.       $texSig == $texAppSign(Textures)} {
  147.         hook::register launch TexturesLaunched $texAppSign(Textures)
  148.         hook::register closeHook TexturescloseHook TeX
  149.     } else {
  150.         hook::deregister launch TexturesLaunched $texAppSign(Textures)
  151.         hook::deregister closeHook TexturescloseHook TeX
  152.     }
  153.     
  154. }
  155.  
  156. proc shadowTeXInputs {args} {
  157.     global packagesSubmenuItems TeXSearchPath
  158.  
  159.     # Reset the Packages submenu so that it will be rebuilt:
  160.     set packagesSubmenuItems ""
  161.     
  162.     message "Rebuilding the Documents submenu…"
  163.     eval [TeX::sub::Documents]
  164.     message ""
  165.  
  166.     # Reset the search path so it will be rebuilt the next time it's needed:
  167.     set TeXSearchPath {}
  168. }
  169.  
  170. # The proc 'shadowUseDollarSigns' is executed automatically whenever 
  171. # the flag 'useDollarSigns' is altered.  The proc 'mathModeSubmenu'
  172. # is defined in latexMenu.tcl.
  173. proc shadowUseDollarSigns {args} {
  174.     TeX::sub::MathModes
  175.     menu::buildSome "Math Modes"
  176. }
  177.  
  178. # we indent to previous non-comment line, +- a bit for \begin or \end
  179. proc TeX::indentLine {} {
  180.     set beg [lineStart [getPos]]
  181.     set text [getText $beg [nextLineStart $beg]]
  182.     regexp {^[ \t]*} $text white
  183.     set next [expr $beg +[string length $white]]
  184.     set lwhite [TeX::correctIndentation [getPos] \
  185.       [getText $next [pos::math $next + 5]]]
  186.     
  187.     set lwhite [text::indentOf $lwhite]
  188.     if {$white != $lwhite} {
  189.         replaceText $beg $next $lwhite
  190.     }
  191.     goto [expr $beg + [string length $lwhite]]
  192. }
  193.  
  194. proc TeX::correctIndentation {pos {next ""}} {
  195.     global indentationAmount
  196.     set beg [lineStart $pos]
  197.  
  198.     # find last non-empty, non-comment line
  199.     if [catch {search -s -f 0 -r 1 -i 0 -m 0 {^[ \t]*[^ \t\r%]} [expr $beg-1]} lst] {
  200.         return 0
  201.     }
  202.     set line [getText [lindex $lst 0] [expr [nextLineStart [lindex $lst 0]] - 1]]
  203.     set lwhite [posX [expr [lindex $lst 1] - 1]]    
  204.     if {[regexp {^[ \t]*\\begin\{} $line]} {
  205.         incr lwhite $indentationAmount
  206.     }
  207.     if [regexp {^\\end\{} $next] {
  208.         incr lwhite -$indentationAmount
  209.     }
  210.     # only happens with poorly formatted files.
  211.     if {$lwhite < 0} {return 0} else {return $lwhite}
  212. }
  213.  
  214. #############################################################################
  215. #
  216. # Colorization
  217. #
  218. #############################################################################
  219.  
  220. newPref v keywordColor blue TeX
  221. newPref v sectionColor magenta TeX
  222. newPref v commentColor red TeX
  223. newPref v bracesColor green TeX
  224.  
  225. # The proc 'shadowCiteRefCommands' is executed whenever the variables 
  226. # TeXmodeVars(citeCommands) or TeXmodeVars(refCommands) are changed.
  227. proc shadowCiteRefCommands {args} {
  228.     global TeXmodeVars
  229.     set LaTeXClickWords {}
  230.     # insure that 'citeCommands' contains "cite" and "nocite":
  231.     lunion TeXmodeVars(citeCommands) cite nocite
  232.     foreach word $TeXmodeVars(citeCommands) { 
  233.         lappend LaTeXClickWords "\\\\$word" 
  234.     }
  235.     # insure that 'refCommands' contains "ref" and "pageref":
  236.     lunion TeXmodeVars(refCommands) ref pageref
  237.     foreach word $TeXmodeVars(refCommands) { 
  238.         lappend LaTeXClickWords "\\\\$word" 
  239.     }
  240.     # color and underline command-double-clickable LaTeX commands:
  241.     regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords
  242. }
  243.  
  244. # The proc 'shadowBoxMacroNames' is executed whenever the variable 
  245. # TeXmodeVars(boxMacroNames) is changed.
  246. proc shadowBoxMacroNames {args} {
  247.     global TeXmodeVars
  248.     set LaTeXClickWords {}
  249.     foreach word $TeXmodeVars(boxMacroNames) { 
  250.         lappend LaTeXClickWords "\\\\$word" 
  251.     }
  252.     # color and underline command-double-clickable LaTeX commands:
  253.     regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords
  254. }
  255.  
  256. proc colorLaTeXClickCommands {} {
  257.     global TeXmodeVars
  258.     lappend LaTeXClickWords \\documentclass \\usepackage \
  259.         \\input \\include \
  260.       \\bibliography \\bibliographystyle \
  261.       \\LoadClass \\RequirePackage 
  262.     # color and underline command-double-clickable LaTeX commands:
  263.     regModeKeywords -a -u -k $TeXmodeVars(keywordColor) TeX $LaTeXClickWords
  264.     shadowCiteRefCommands
  265.     shadowBoxMacroNames
  266. }
  267.  
  268. proc colorLaTeXCommands {} {
  269.     global TeXmodeVars 
  270.     set LaTeXKeyWords {}
  271.     # Color comments, braces and dollar signs, and all LaTeX commands:
  272.     regModeKeywords -i "\}" -i "\{" -i "\$" -I $TeXmodeVars(bracesColor) \
  273.       -e {%} -m {\\} -c $TeXmodeVars(commentColor) \
  274.       -k $TeXmodeVars(keywordColor) TeX $LaTeXKeyWords
  275.     # Color sectioning commands:
  276.     regModeKeywords -a -k $TeXmodeVars(sectionColor) TeX \
  277.       { \\part \\chapter \\section \\subsection \\subsubsection \\paragraph }
  278. }
  279.  
  280. colorLaTeXCommands; rename colorLaTeXCommands ""
  281. colorLaTeXClickCommands; rename colorLaTeXClickCommands ""
  282.  
  283. #############################################################################
  284. #
  285. # LaTeX initialisation
  286. #
  287. #############################################################################
  288.  
  289. if [alpha::try "Initialising LaTeX" \
  290.   latexEngine.tcl {} \
  291.   latexComm.tcl {}\
  292.   latexMacros.tcl {}\
  293.   latexMenu.tcl {} \
  294.   latexKeys.tcl {} \
  295.   bindLaTeXKeys {Binding LaTeX keys} \
  296.   [list app::registerMultiple tex [list OTEX *TEX *XeT MPS*] \
  297.   [list •266 •267 •272 •299] shadowtexSig] {Building LaTeX menu}] {
  298.     rename bindLaTeXKeys ""
  299. }
  300.